package servlet.admin;

import com.alibaba.fastjson.JSONObject;
import pojo.Order;
import pojo.User2;
import service.OrderService;
import service.UserLoginService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/searchorderlist")
public class SearchOrderrList extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        OrderService orderService = new OrderService();
        List<Order> orders = orderService.selectOrder();
        JSONObject jsonResponse = new JSONObject();
        //当前页数
        String currentPage = req.getParameter("currentPage");
        //每页展示的数据
        String pageSize = req.getParameter("pageSize");
        // 转换currentPage和pageSize为整数
        int page = Integer.parseInt(currentPage);
        int size = Integer.parseInt(pageSize);
        int startIndex = (page - 1) * size;
        int endIndex = Math.min(startIndex + size, orders.size());
        List<Order> currentPageUsers = orders.subList(startIndex, endIndex);
        jsonResponse.put("orderList", currentPageUsers); // 添加books列表
        jsonResponse.put("size", orders.size()); // 添加books大小信息
        String jsonString = jsonResponse.toJSONString();
        PrintWriter writer = resp.getWriter();
        writer.write(jsonString);
    }

}
